// HeightMapGenerator.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "HeightMap.h"


int _tmain(int argc, _TCHAR* argv[])
{
	FreeImage_Initialise();
	apr_initialize();

	// apr mem pool
	apr_pool_t *pool = NULL;
	apr_pool_create(&pool, NULL);
	assert(pool);

	// default parameters
	int w = 1024, h = 1024, iterTimes = 100;
	float maxDelta = 0.8f, minDelta = 0.01f, filter = 0.3f; 
	const char *filePath = ".\\HeightMap.jpg";
	
	//
	// opt
	//
	apr_getopt_t *opt = NULL;
	apr_getopt_init(&opt, pool, argc, argv);
	const char *optArg = NULL;
	apr_getopt_option_t longOpt[] = 
		{{"width", 'w', 1, "map width"},
		 {"height", 'h', 1, "map height"},
		 {"iterTimes", 't', 1, "iterate times"},
		 {"maxDelta", 'a', 1, "max delta"},
		 {"minDelta", 'b', 1, "min delta"},
		 {"filePath", 'f', 1, "file path"},
		 {"filter", 'i', 1, "filter(0.3~0.f,ref <<Focus On 3D Terrain Rendering>>)"},
		};
	int optChar = 0;
	while (apr_getopt_long(opt, longOpt, &optChar, &optArg) == APR_SUCCESS)
	{
		switch (optChar)
		{
		case 'w':
			w = atoi(optArg);
			break;
		case 'h':
			h = atoi(optArg);
			break;
		case 't':
			iterTimes = atoi(optArg);
			break;
		case 'a':
			maxDelta = atof(optArg);
			break;
		case 'b':
			minDelta = atof(optArg);
			break;
		case 'f':
			filePath = optArg;
			break;
		case 'i':
			filter = atof(optArg);
			break;
		default:
			assert(false);
			return -1;
		}
	}
	

	///////////////////////

	int ret = GenHMJpegFile(filePath, w, h, iterTimes, maxDelta, minDelta, filter);

	apr_pool_destroy(pool);

	apr_terminate();
	FreeImage_DeInitialise();

	return 0;
}